package global.com.loansapplication.ui.actviity.user.presenter;

import java.util.List;

import javax.inject.Inject;

import global.com.loansapplication.base.BaseBean;
import global.com.loansapplication.base.BaseBiz;
import global.com.loansapplication.bean.ClueInfo;
import global.com.loansapplication.comm.MyApplication;
import global.com.loansapplication.ui.actviity.user.biz.ExportBiz;
import global.com.loansapplication.ui.actviity.user.contract.ExportContract;
import global.com.loansapplication.util.ExcelUtil;

/**
 * Created by Administrator on 2017/10/21.
 */

public class ExportPresenter implements ExportContract.Presenter {

    ExportContract.View view;
    ExportBiz exportBiz;


    @Inject
    public ExportPresenter(ExportContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        exportBiz = (ExportBiz) biz;
    }

    @Override
    public void addSuggest(String startTime, String endTime, String customerType) {
        view.loading(true);
        exportBiz.getClueList(MyApplication.userInfo.getUserCode(), startTime, endTime, customerType, new BaseBiz.Callback<BaseBean<List<ClueInfo>>>() {
            @Override
            public void onSuccess(BaseBean<List<ClueInfo>> o) {
                if(o.getList().size()>0){
                    view.showMsg("正在保存文件。。。");
                    view.saveData(o.getList());
                }else {
                    view.showMsg("未找到对应的购买记录");
                }
                view.loading(false);
            }

            @Override
            public void onFailure(BaseBean<List<ClueInfo>> o) {
                view.loading(false);
            }
        });
    }

    @Override
    public void addCustom(String startTime, String endTime, String customerType) {
        view.loading(true);
        exportBiz.getBatchInfoByUserId(MyApplication.userInfo.getUserCode(), startTime, endTime, customerType, new BaseBiz.Callback<BaseBean<List<ClueInfo>>>() {
            @Override
            public void onSuccess(BaseBean<List<ClueInfo>> o) {
                if(o.getList().size()>0){
                    view.showMsg("正在保存文件。。。");
                    view.saveData(o.getList());
                }else {
                    view.showMsg("未找到对应的购买记录");
                }
                view.loading(false);
            }

            @Override
            public void onFailure(BaseBean<List<ClueInfo>> o) {
                view.loading(false);
            }
        });
    }
}
